package 字符串压缩;

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param param string字符串
     * @return string字符串
     */
    public String compressString(String param) {
        int n = param.length();
        StringBuilder ret = new StringBuilder("");
        for (int i = 0, j = 0; i < n; i++) {
            ret.append(param.charAt(i));
            j = i + 1;
            while (j < n && param.charAt(j) == param.charAt(i)) {
                j++;
            }
            if (j <= n && j != i + 1) {
                ret.append(j - i);
            }
            i = j - 1;
        }
        return ret.toString();
    }
}